package com.zhang.admin.service.impl;

import com.zhang.admin.dao.SysElementMapper;
import com.zhang.admin.po.SysElement;
import com.zhang.admin.service.ElementService;
import com.zhang.admin.vo.CreateUpdateElementParams;
import com.zhang.common.core.constant.StatusConstant;
import com.zhang.common.core.util.EntityUtil;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description
 * @Author zsw
 * @Date 2019/11/19 16:53
 * @Version V1.0
 **/
@Service
@AllArgsConstructor
public class ElementServiceImpl implements ElementService {
    private final SysElementMapper sysElementMapper;
    @Override
    public List<SysElement> queryAll() {
        return sysElementMapper.queryAll();
    }

    @Override
    public List<SysElement> queryElementByRoleId(Integer roled) {
        return sysElementMapper.queryElementByRoleId(roled, StatusConstant.DELETE_FLAG_N);
    }

    @Override
    public List<SysElement> queryElementByUsername(String username) {
        return sysElementMapper.queryElementByUsername(username,StatusConstant.DELETE_FLAG_N);
    }

    @Override
    public SysElement queryEleMentById(Integer id) {
        return sysElementMapper.selectByPrimaryKey(id);
    }

    @Override
    public void createElement(CreateUpdateElementParams createUpdateElementParams) {
        //TODO 验重 name
        SysElement sysElement = new SysElement();
        EntityUtil.setCreatAndUpdatInfo(sysElement);
        BeanUtils.copyProperties(createUpdateElementParams, sysElement);
        sysElementMapper.insertSelective(sysElement);
    }

    @Override
    public void updateElement(CreateUpdateElementParams createUpdateElementParams) {
        //TODO 验重 name
        SysElement sysElement = new SysElement();
        EntityUtil.setUpdatedInfo(sysElement);
        BeanUtils.copyProperties(createUpdateElementParams, sysElement);
        sysElementMapper.updateByPrimaryKeySelective(sysElement);
    }




}